/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ia_project;

import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QDesktopWidget;
import com.trolltech.qt.gui.QGroupBox;
import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QLCDNumber;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QMessageBox;
import com.trolltech.qt.gui.QPixmap;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QSlider;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;

/**
 *
 * @author Utilisateur
 */
public class MainWindow extends QWidget{
    
   // public final Signal0 s_creerWorld = new Signal0();
    private QLCDNumber lcd;

    public QLCDNumber getLcd() {
        return lcd;
    }
    
    public MainWindow()
    {
        /***************centrer la fenetre à l'ecran*************************************/
        QDesktopWidget widget = QApplication.desktop();
        int desktop_width = widget.width();
        int desktop_height = widget.height();
        int x = desktop_width / 2 - width() / 2;
        int y = desktop_height / 2 - height() / 2 - 25;
        move(new QPoint(x, y));
        /********************************************************************************/
        
        this.setWindowTitle("Générateur de monde");
        this.setWindowIcon(new QIcon("./img/logo.png"));
        
        QPixmap pig = new QPixmap("./img/splashScreen.png");
        pig.scaled(400, 100);
        QLabel image = new QLabel(); 
        image.setPixmap(pig);
        
        QGroupBox population = new QGroupBox("Population");
        lcd = new QLCDNumber(3);
        lcd.setFixedHeight(100);
        lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Flat);
        
        QSlider slider = new QSlider(Orientation.Horizontal);
        slider.setRange(0, 200);
        slider.setValue(0);
        slider.valueChanged.connect(lcd, "display(int)");
        
        QVBoxLayout populationLayout = new QVBoxLayout();
        populationLayout.addWidget(lcd);
        populationLayout.addWidget(slider);
        population.setLayout(populationLayout);
        
        QPushButton btn_creerWorld = new QPushButton("Créer un monde");
        btn_creerWorld.clicked.connect(this, "creerWorld()");
        
        QVBoxLayout layout = new QVBoxLayout();
        layout.addWidget(image);
        layout.addWidget(population);
        layout.addWidget(btn_creerWorld);
        setLayout(layout);
    }
    
    public void creerWorld()
    {
        if((int)this.getLcd().value() > 0)
        {
            WorldWindow world = new WorldWindow((int)this.getLcd().value());
            world.show();
            this.close();
        }
        else
            QMessageBox.critical(this, "Erreur", "Le monde doit contenir au moins un individu");
    }
}
